<% content_for :page_title do %>
  <%= link_to Spree.t(:option_types), spree.admin_option_types_url %> /
  <%= @option_type.name %>
<% end %>

<% content_for :page_actions do %>
  <span id="new_add_option_value" data-hook>
    <%= button_link_to Spree.t(:add_option_value), "javascript:;", { icon: 'add.svg', :'data-target' => "tbody#sortVert", class: 'btn-success spree_add_fields' } %>
  </span>
<% end %>

<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @option_type } %>

<%= form_for [:admin, @option_type] do |f| %>
  <div class="card mb-3">
    <div class="card-header">
      <h1 class="card-title mb-0 h5">
        <%= Spree.t(:option_values) %>
      </h1>
    </div>
    <div class="card-body">
      <%= render partial: 'form', locals: { f: f } %>
    </div>
    <div class="table-responsive">
      <table class="table table-condensed sortable" data-hook data-sortable-link="<%= update_values_positions_admin_option_types_url %>">
        <thead data-hook="option_header">
          <tr>
            <th colspan="2"><%= Spree.t(:name) %> <span class="required">*</span></th>
            <th><%= Spree.t(:display) %> <span class="required">*</span></th>
            <th class="actions"></th>
          </tr>
        </thead>
        <tbody id="sortVert">
          <% if @option_type.option_values.empty? %>
            <tr id="none" data-hook="option_none">
              <td colspan="2"><%= Spree.t(:none) %></td>
              <td class="actions text-center"></td>
            </tr>
          <% else %>
            <%= f.fields_for :option_values do |option_value_form| %>
              <%= render partial: 'option_value_fields', locals: { f: option_value_form } %>
            <% end %>
          <% end %>
        </tbody>
      </table>
    </div>
    <div class="card-footer text-center">
      <%= render partial: 'spree/admin/shared/edit_resource_links' %>
    </div>
  </div>
<% end %>
